package org.ccay.validator.validators;

import com.opensymphony.xwork2.validator.ValidatorContext;
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;

/**
 * 字段级验证的抽象类
 * 
 * 增加字段国际化属性
 * 将fieldLabel设置为默认第一个参数
 * 
 * 
 *
 */
public abstract class AbstractFieldValidator extends FieldValidatorSupport {

	/** 字段国际化名称 */
    private String fieldLabel;
	/** 字段国际化key */
    private String fieldLabelKey;
	public String getFieldLabel() {
		return fieldLabel;
	}
	public void setFieldLabel(String fieldLabel) {
		this.fieldLabel = fieldLabel;
	}
	public String getFieldLabelKey() {
		return fieldLabelKey;
	}
	public void setFieldLabelKey(String fieldLabelKey) {
		this.fieldLabelKey = fieldLabelKey;
	}

	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.validator.validators.ValidatorSupport#getMessage(java.lang.Object)
	 */
	@Override
    public String getMessage(Object object) {
    	// 设置字段国际化名称
		if (null != fieldLabelKey) {
	    	ValidatorContext ctx = getValidatorContext();
	    	setFieldLabel( ctx.getText(fieldLabelKey) );
		}

        return super.getMessage(object);
    }
	
}
